package com.demo.zhou.sniper.application;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import androidx.multidex.MultiDex;

import com.demo.zhou.sniper.gen.DaoMaster;
import com.demo.zhou.sniper.gen.DaoSession;

import org.greenrobot.greendao.database.Database;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhou on 2017/4/15.
 */

public class MyApplication extends Application{
    private static MyApplication mApplication = null;
    /**是否加密标志。通过这个例子展示给我们greendao从用SQLCipher加密数据库到标准的sqlite切换时多么简单.打开数据库加密需要引入SQLCipher相关的库*/
    public static final boolean ENCRYPTED = false;

    /**全局公用的DaoSession**/
    private DaoSession daoSession;
    private List<Activity> activities = new ArrayList<Activity>();
    public List<Activity> getActivities(){
        return activities;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        mApplication = this;
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, ENCRYPTED ? "sniper-db-encrypted" : "sniper-db");
        Database db = ENCRYPTED ? helper.getEncryptedWritableDb("super-secret") : helper.getWritableDb();
        daoSession = new DaoMaster(db).newSession();
    }
    public static MyApplication getInstance() {
            return mApplication;

    }
    public DaoSession getDaoSession() {
        return daoSession;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }
}
